package com.example.demo.controller;

import com.example.demo.entity.User;
import com.example.demo.service.UserService;
import com.example.demo.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/user")
@Api("用户管理")
public class UserController {

    @Autowired
    UserService userService;

    @ApiOperation("测试方法")
    @RequestMapping("/select")
    public List<User> select(){
        return userService.select();
    }

    @ApiOperation("登录")
    @RequestMapping("/login")
    public Result login(User user){
        return userService.login(user);
    }

    @ApiOperation("注册")
    @GetMapping("/register")
    public Result register(User user){
        return userService.register(user);
    }

    @ApiOperation("新增")
    @RequestMapping("/add")
    public Result add(User user){
        return (Result) userService.add(user);
    }

    @ApiOperation("退出")
    @GetMapping("/exit")
    public Result exit(HttpServletRequest rq){

        return  userService.exit(rq.getHeader("token"));
    }


}
